<?php

namespace app\backstage\model;

use think\Model;
use think\model\concern\SoftDelete;
use think\Validate;
class Admin extends Model
{   

    protected $name = 'rbac_admin';
    use SoftDelete;
    protected $deleteTime = 'delete_time';

     //验证数据
     public function valiData($data){
        
        $validate = new Validate([
            'name'  => 'require',
            'phone'  => 'require',
            'email' => 'email',
            '__token__' => 'require|token',
        ]);
            
        
        if (!$validate->check($data)) {
            return ['code'=>101,'msg'=>$validate->getError()];
        }
        
        if(!empty($data['id'])){
            $row = $this->where("id <> {$data['id']} and (phone='{$data['phone']}' or email = '{$data['email']}')")->find();
            
        }else{
            $row = $this->where('phone',$data['phone'])->whereOr('email',$data['email'])->find();
            
        }

        if($row){
            return ['code'=>101,'msg'=>'手机号或邮箱已被注册'];
        }

        return ['code'=>200];

    }
}
